#include <iostream>
#include <stack>

using namespace std;
typedef long long LL;
const int N = 3e6 + 10;
int n;
LL a[N];
LL ret[N];
int main()
{
	cin >> n;
	for (int i = 1; i <= n ; i++)
		cin >> a[i];
	stack<LL> st;
	for (int i = n; i >= 1; i--)
	{
		while (st.size() && a[st.top()] <= a[i])
			st.pop();
		if(st.size())ret[i] = st.top();
		st.push(i);

	}
	for (int i = 1; i <= n; i++)
		cout << ret[i] << " ";
	cout << endl;
	return 0;
}